// ==UserScript==
// @name         东奥教育微信检测绕过
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  绕过东奥教育网页的微信环境检测
// @author       DarkSheep
// @match        https://study.dongao.cn/h5/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    
    // 在页面加载前注入代码
    const script = document.createElement('script');
    script.textContent = `
        // 重写检测方法
        const originalUtil = {
            isDevice: window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger",
            isWeChat: window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger",
            isMobile: function() {
                return 2; // 返回2表示iOS设备
            },
            isDD: false,
            isZjApp: false,
            isJxApp: false,
            isAliplay: false
        };

        // 重写Object.defineProperty以拦截userAgent的获取
        const originalDefineProperty = Object.defineProperty;
        Object.defineProperty = function(obj, prop, descriptor) {
            if(prop === 'userAgent') {
                descriptor.get = function() {
                    return 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.0(0x18000000) NetType/WIFI Language/zh_CN';
                }
            }
            return originalDefineProperty(obj, prop, descriptor);
        };

        // 重写navigator.userAgent
        Object.defineProperty(navigator, 'userAgent', {
            get: function() {
                return 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.0(0x18000000) NetType/WIFI Language/zh_CN';
            }
        });

        // 监听Vue实例创建
        let vueInitialized = false;
        Object.defineProperty(window, '__vue_app__', {
            set: function(app) {
                if(!vueInitialized && app) {
                    vueInitialized = true;
                    
                    // 重写Vue实例中的检测方法
                    if(app.config && app.config.globalProperties && app.config.globalProperties.$util) {
                        Object.keys(originalUtil).forEach(key => {
                            if(typeof originalUtil[key] === 'function') {
                                app.config.globalProperties.$util[key] = originalUtil[key];
                            } else {
                                Object.defineProperty(app.config.globalProperties.$util, key, {
                                    get: () => originalUtil[key]
                                });
                            }
                        });
                    }
                }
                return app;
            },
            get: function() {
                return window.__vue_app__;
            }
        });
    `;
    document.documentElement.appendChild(script);

    // 注入CSS
    const style = document.createElement('style');
    style.textContent = `
        .app-hide {
            display: block !important;
        }
        .wechat-hide {
            display: block !important;
        }
    `;
    document.head.appendChild(style);

    // 监听路由变化
    window.addEventListener('load', function() {
        const observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                if(mutation.type === 'childList') {
                    // 处理新加载的元素
                    const elements = document.querySelectorAll('.app-hide, .wechat-hide');
                    elements.forEach(el => {
                        el.style.display = 'block';
                    });
                }
            });
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
})();